import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../helper/uidata.dart';
import '../../model/doc_review.dart';
import '../../pages/baobiao/day_data_list.dart';
import '../../pages/baobiao/hour_data_list.dart';
import '../../pages/baobiao/res_swxg.dart';
import '../../pages/baobiao/res_xlnl.dart';
import '../../pages/calculate/calculate.dart';
import '../../pages/calculate/linedemo.dart';
import '../../pages/cleanobjects/cleanobjects_list2.dart';
import '../../pages/danger2/danger_list2.dart';
import '../../pages/docreview/docreview_list.dart';
import '../../pages/docsend/docsend_list.dart';
import '../../pages/inspectreport/inspectReport_list.dart';
import '../../pages/sdzx/sdzx_data_ss.dart';
import '../../pages/sdzx/things_manage.dart';
import '../../pages/sdzx/work_record.dart';
import '../../pages/skddl2/skddl_list.dart';
import '../../pages/things/inventory_list.dart';
import '../../pages/things/things_list.dart';
import '../../pages/things/things_select.dart';

import '../../helper/menuHelper.dart';
import '../../helper/routeHelper.dart';
import '../../pages/baobiao/jinqi_dd.dart';
import '../../pages/danger/danger_list.dart';
import '../../pages/homex/download_list.dart';
import '../../pages/homex/upfile_list.dart';
import '../../pages/sdzx/sdzx_helper.dart';

import '../../spaces/filespace/fileSpace_list.dart';
import '../../pages/jxgzp/jxgzp_list.dart';
import '../../pages/security/security_list.dart';
import '../../pages/shipuse/shipuse_list.dart';
import '../../pages/skddl/skddl_list.dart';
import '../../pages/station/station_list.dart';
import '../../pages/xhss/xhss_info.dart';
import '../../spaces/movie_space/movie_play.dart';
import '../../spaces/movie_space/record_list.dart';
import '../../spaces/spaceX/spacex_list.dart';
import '../../widgets/IconWidget.dart';
import '../../widgets/ImgWidget.dart';

import '../../widgets/menu_item.dart';

class SdzxWorkPage extends StatefulWidget {
  @override
  SdzxWorkPage();

  @override
  SdzxWorkPageState createState() => new SdzxWorkPageState();
}

class SdzxWorkPageState extends State<SdzxWorkPage> {
  late Map<int, List<MenuItemViewModel>> mList;
  late List<MenuItemViewModel> mL1;
  late List<MenuItemViewModel> mL2;
  late List<MenuItemViewModel> mL3;
  late List<MenuItemViewModel> mL4;
  late List<MenuItemViewModel> mL5;
  var shipIcon = const Icon(IconData(0xe766, fontFamily: 'alFonts'),
      size: 28.0, color: Colors.white);
  bool ifLoaded = false;
  late String authority;
  @override
  void initState() {
    // TODO: implement initState

    super.initState();
    //  getML();
    LoadData();
  }

  Icon getIcon(IconData d1) {
    return Icon(d1, size: 28.0, color: Colors.white);
  }

  Icon getAlIcon(int x) {
    return getIcon(IconData(x, fontFamily: 'alFonts'));
  }

  void LoadData() async {
    authority = UIData.CurrentUser!.Position;
    if (authority == null) authority = "";

    getML(this.context);
    //print(sz);
    setState(() {
      ifLoaded = true;
    });

    //ChannelHelper.showToast("更新完成!");
  }

  void getML(BuildContext ctx) {
    print('getML');
    mList = new Map<int, List<MenuItemViewModel>>();
    mList[0] = <MenuItemViewModel>[];
    mList[1] = <MenuItemViewModel>[];
    mList[2] = <MenuItemViewModel>[];
    mList[3] = <MenuItemViewModel>[];
    getML0(ctx);
    getML1(ctx);
    getML2(ctx);
    getML3(ctx);
  }

  void getML0(BuildContext ctx) {
    addMenu(
        0,
        getMenu(
            getIcon(Icons.donut_small),
            "发电负荷",
            () => RouteHelper.ShowPage(
                context,
                DCSSDataPage(
                  ifAppBar: true,
                ))));
    addMenu(
        0,
        getMenu(getIcon(Icons.collections), "近期调度",
            () => RouteHelper.ShowPage(context, JinQiDiaoDuPage())));

    //  addMenu(0, getMenu(getIcon(Icons.line_weight), "日报查询", ()=>RouteHelper.ShowPage(context, JinQiDiaoDuPage())));
    addMenu(
        0,
        getMenu(getIcon(Icons.equalizer), "日报统计",
            () => RouteHelper.ShowPage(context, DayDataListPage()),
            ifCheck: true));
    addMenu(
        0,
        getMenu(getIcon(Icons.drag_handle), "时段查询",
            () => RouteHelper.ShowPage(context, HourDataListPage()),
            ifCheck: true));

    //addMenu(0, getMenu(getIcon(Icons.line_weight), "数据统计", null));
    addMenu(
        0,
        getMenu(getIcon(Icons.opacity), "水位相关",
            () => RouteHelper.ShowPage(context, ResSwKrPage())));
    addMenu(
        0,
        getMenu(getIcon(Icons.vignette), "泄洪流量",
            () => RouteHelper.ShowPage(context, ResXLNLPage())));
    addMenu(
        0,
        getMenu(getIcon(Icons.vignette), "优化调度",
            () => RouteHelper.ShowPage(context, CalculatePage())));
    addMenu(
        0,
        getMenu(
            getIcon(Icons.vignette),
            "界面试验",
            () => RouteHelper.ShowPage(
                context, SelectionCallbackExample.withSampleData())));

    //addMenu(0, getMenu(getIcon(Icons.gps_not_fixed), "泄洪设施状态", ()=>RouteHelper.ShowPage(ctx,XHSSInfoPage(true) )));
    //addMenu(0, getMenu(getIcon(Icons.assessment), "专题统计", null));
    // addMenu(0, getMenu(getIcon(Icons.opacity), "水位相关", null));
    // addMenu(0, getMenu(getIcon(Icons.leak_add), "振动区查询", null));
  }

  void getML1(BuildContext ctx) {
    addMenu(
        1,
        getMenu(getIcon(Icons.device_hub), "水库调度令",
            () => RouteHelper.ShowPage(ctx, SKDDL2ListPage(true))));
    // addMenu(
    //     1,
    //     getMenu(getIcon(Icons.track_changes), "泄洪洞检修",
    //         () => RouteHelper.ShowPage(ctx, JxgzpListPage(true))));
    addMenu(
        1,
        getMenu(shipIcon, "用船申请审批",
            () => RouteHelper.ShowPage(ctx, ShipUseListPage(true))));
    //addMenu(1, getMenu(getIcon(Icons.crop), "建议运行", ()=>RouteHelper.ShowPage(ctx,DocSendListPage(true))));
    addMenu(
        1,
        getMenu(
            getIcon(Icons.crop),
            "建议运行",
            () =>
                RouteHelper.ShowPage(ctx, DocReviewListPage(true, 1, "建议运行"))));
    // addMenu(
    //     1,
    //     getMenu(
    //         getIcon(Icons.gradient),
    //         "发电计划",
    //         () =>
    //             RouteHelper.ShowPage(ctx, DocReviewListPage(true, 2, "发电计划"))));
    // addMenu(
    //     1,
    //     getMenu(
    //         getIcon(Icons.insert_drive_file),
    //         "水调行文",
    //         () =>
    //             RouteHelper.ShowPage(ctx, DocReviewListPage(true, 3, "水调行文"))));
    // addMenu(
    //     1,
    //     getMenu(
    //         getIcon(Icons.health_and_safety),
    //         "库区安全",
    //         () =>
    //             RouteHelper.ShowPage(ctx, DocReviewListPage(true, 4, "库区安全"))));
    // addMenu(
    //     1,
    //     getMenu(
    //         getIcon(Icons.date_range_outlined),
    //         "水情报告",
    //         () =>
    //             RouteHelper.ShowPage(ctx, DocReviewListPage(true, 5, "水情报告"))));
  }

  void getML2(BuildContext ctx) {
    addMenu(
        2,
        getMenu(getIcon(Icons.verified_user), "安全检查",
            () => RouteHelper.ShowPage(context, SecurityCheckListPage())));
    addMenu(
        2,
        getMenu(getIcon(Icons.help), "问题处理",
            () => RouteHelper.ShowPage(ctx, DangerListPage(true, "")),
            ifCheck: true));
    addMenu(
        2,
        getMenu(getIcon(Icons.warning), "隐患登记",
            () => RouteHelper.ShowPage(ctx, Danger2ListPage(true)),
            ifCheck: true));
    addMenu(
        2,
        getMenu(getIcon(Icons.local_shipping), "清漂运输",
            () => RouteHelper.ShowPage(ctx, CleanObjectsList2Page(true)),
            ifCheck: true));
    addMenu(
        2,
        getMenu(getIcon(Icons.directions_bike), "库区巡查",
            () => RouteHelper.ShowPage(ctx, InspectReportListPage())));
    addMenu(
        2,
        getMenu(getIcon(Icons.location_on), "测站巡检",
            () => RouteHelper.ShowPage(ctx, StationBookPage(ifAppbar: true)),
            ifCheck: true));
    addMenu(
        2,
        getMenu(getIcon(Icons.stars), "物资管理",
            () => RouteHelper.ShowPage(ctx, ThingsManagePage()),
            ifCheck: true));

    // addMenu(2, getMenu(getIcon(Icons.view_list), "待办事项", null));
  }

  void getML3(BuildContext ctx) {
    // addMenu(3, getMenu(getIcon(Icons.view_headline), "收文登记", ()=>RouteHelper.ShowPage(context, MovieListPage(SdzxHelper.projectRecord,true,2))));
    // addMenu(3, getMenu(getIcon(Icons.description), "发文登记",  ()=>RouteHelper.ShowPage(context, MoviePlayPage("5F141544-BEA6-4A3D-A437-5B6D5D8C8517"))));
    //addMenu(3, getMenu(getIcon(Icons.widgets), "项目管理", null));
    //addMenu(3, getMenu(getIcon(Icons.widgets), "项目记录", ()=>RouteHelper.ShowPage(context, SpaceXListPage(SdzxHelper.projectRecord,"项目记录",IconWidget.getImage(Colors.blue,Icons.widgets)))));

    //addMenu(3, getMenu(getIcon(Icons.remove_red_eye), "考察调研", null));
    //addMenu(3, getMenu(getIcon(Icons.remove_red_eye), "考察调研", ()=>RouteHelper.ShowPage(context, SpaceXListPage(SdzxHelper.researchRecord,"考察调研",IconWidget.getImage(Colors.blue,Icons.remove_red_eye)))));

    //addMenu(3, getMenu(getIcon(Icons.move_to_inbox), "会议记录", ()=>RouteHelper.ShowPage(context, SpaceXListPage(SdzxHelper.meetRecord,"会议记录",IconWidget.getImage(Colors.blue,Icons.move_to_inbox)))));
    //addMenu(3, getMenu(getIcon(Icons.flag), "党建活动", ()=>RouteHelper.ShowPage(context, SpaceXListPage(SdzxHelper.flagRecord,"党建活动",IconWidget.getImage(Colors.blue,Icons.flag)))));
    // addMenu(3, getMenu(getIcon(Icons.folder), "文件资料", ()=>RouteHelper.ShowPage(ctx,UpFileBookPage() )));

    addMenu(
        3,
        getMenu(getIcon(Icons.folder), "文档管理",
            () => RouteHelper.ShowPage(ctx, FileSpaceListPage()),
            ifCheck: true));
    addMenu(
        3,
        getMenu(getIcon(Icons.camera_alt), "工作记录",
            () => RouteHelper.ShowPage(ctx, WorkRecordPage()),
            ifCheck: true));
    //addMenu(3, getMenu(getIcon(Icons.folder), "记录浏览", ()=>RouteHelper.ShowPage(ctx, FileSpaceListPage())));
    //addMenu(3, getMenu(getIcon(Icons.folder), "照片视频", ()=>RouteHelper.ShowPage(ctx, FileSpaceListPage())));

    // addMenu(3, getMenu(getIcon(Icons.image), "照片视频", ()=>RouteHelper.ShowPage(ctx, FileSpaceListPage())));
    addMenu(
        3,
        getMenu(
            getIcon(Icons.cloud_upload),
            "上传列表",
            () => RouteHelper.ShowPage(
                ctx,
                UpFileBookPage(
                  ifAppbar: true,
                ))));
    addMenu(
        3,
        getMenu(
            getIcon(Icons.cloud_download),
            "下载列表",
            () => RouteHelper.ShowPage(
                ctx,
                DownLoadBookPage(
                  ifAppbar: true,
                ))));
  }

  void addMenu(int xh, MenuItemViewModel m1) {
    if (m1 == null) return;

    if (m1 != null) {
      mList[xh]!.add(m1);
    }
  }

  MenuItemViewModel getMenu(Icon icon1, String title, VoidCallback onTap,
      {bool ifCheck = false}) {
    if (!ifCheck) {
      return MenuItemViewModel(icon1, title, onTap);
    }

    if (authority == "all" || authority.contains(title)) {
      return MenuItemViewModel(icon1, title, onTap);
    } else {
      return null as MenuItemViewModel;
    }
  }

  @override
  Widget build(BuildContext context) {
    //getML(context);
    return Scaffold(
      //backgroundColor: Colors.white,
      // appBar: new AppBar(
      // title: bottomTabs[currentIndex].title,
      //title: Text("断面详情")),
      floatingActionButton: getFloatingButton(context),
      body: SdzxWorkBody(context),
    );
  }

  Widget getFloatingButton(BuildContext context) {
    return new Container();
  }

  List<Widget> getWidgetList(BuildContext context) {
    List<Widget> list1 = <Widget>[];
    // getML(context);
    list1.add(MenuHelper.getMenuCard(
        "数据查询",
        mList[0]!.map((item) => MenuItem1(data: item)).toList()
            as List<Widget>));
    list1.add(MenuHelper.getMenuCard(
        "在线审批",
        mList[1]!.map((item) => MenuItem1(data: item)).toList()
            as List<Widget>));
    list1.add(MenuHelper.getMenuCard(
        "电子报表",
        mList[2]!.map((item) => MenuItem1(data: item)).toList()
            as List<Widget>));
    list1.add(MenuHelper.getMenuCard(
        "综合办公",
        mList[3]!.map((item) => MenuItem1(data: item)).toList()
            as List<Widget>));
    // list1.add( MenuHelper.getMenuCard(f2t3534e423"实用工具",mL5.map((item) => MenuItem(data: item)).toList()));
    // list1.add( MenuHelper.getMenuCard("数据查询",mList.map((item) => MenuItem(data: item)).toList()));

    return list1;
  }

  SdzxWorkBody(BuildContext context) => SingleChildScrollView(
        child: SdzxWorkFields(context),
      );

  SdzxWorkFields(BuildContext context) {
    if (!ifLoaded)
      return Center(
          child: SpinKitCircle(
        color: Colors.blue,
      ));
    return Container(child: Column(children: getWidgetList(context)));
  }
}
